/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    vertex_leaf_deferred.h
 * Desc:    Mesh leaf deferred shader
 * Version: 1.06
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

/******************************************************************************\
*
* OpenGL
*
\******************************************************************************/

#ifdef OPENGL
	
	#ifndef VERTEX_LEAF_DEFERRED
		#define VERTEX_LEAF_DEFERRED
		
	#else
		
		gl_Position = getPosition(vertex);
		
		s_texcoord_0.xy = texcoord.xy;
		
		float distance = length(vertex.xyz) * s_depth_range.w;
		
		#ifdef QUALITY_MEDIUM && PHONG
			s_texcoord_1 = float4(tangent.x,binormal.x,normal.x,distance);
			s_texcoord_2.xyz = float3(tangent.y,binormal.y,normal.y);
			s_texcoord_3.xyz = float3(tangent.z,binormal.z,normal.z);
		#else
			#ifdef LEAFS_BILLBOARD
				s_texcoord_1 = float4(0.0f,0.0f,1.0f,distance);
			#else
				s_texcoord_1 = float4(normal,distance);
			#endif
		#endif
		
		#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
			s_texcoord_9.x = alpha_fade;
		#endif
		
	#endif
	
/******************************************************************************\
*
* Direct3D11
*
\******************************************************************************/

#elif DIRECT3D11
	
	#ifndef VERTEX_LEAF_DEFERRED
		#define VERTEX_LEAF_DEFERRED
		
		struct VERTEX_OUT {
			float4 position : OUT_POSITION;
			float2 texcoord_0 : TEXCOORD0;
			float4 texcoord_1 : TEXCOORD1;
			#ifdef QUALITY_MEDIUM && PHONG
				float3 texcoord_2 : TEXCOORD2;
				float3 texcoord_3 : TEXCOORD3;
			#endif
			#ifdef NOISE
				float3 texcoord_8 : TEXCOORD8;
			#endif
			#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
				float1 texcoord_9 : TEXCOORD9;
			#endif
		};
		
	#else
		
		OUT.position = getPosition(vertex);
		
		OUT.texcoord_0 = texcoord.xy;
		
		float distance = length(vertex.xyz) * s_depth_range.w;
		
		#ifdef QUALITY_MEDIUM && PHONG
			OUT.texcoord_1 = float4(tangent.x,binormal.x,normal.x,distance);
			OUT.texcoord_2 = float3(tangent.y,binormal.y,normal.y);
			OUT.texcoord_3 = float3(tangent.z,binormal.z,normal.z);
		#else
			#ifdef LEAFS_BILLBOARD
				OUT.texcoord_1 = float4(0.0f,0.0f,1.0f,distance);
			#else
				OUT.texcoord_1 = float4(normal,distance);
			#endif
		#endif
		
		#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
			OUT.texcoord_9.x = alpha_fade;
		#endif
		
	#endif
	
/******************************************************************************\
*
* Direct3D9
*
\******************************************************************************/

#elif DIRECT3D9
	
	#ifndef VERTEX_LEAF_DEFERRED
		#define VERTEX_LEAF_DEFERRED
		
		struct VERTEX_OUT {
			float4 position : POSITION;
			float2 texcoord_0 : TEXCOORD0;
			float4 texcoord_1 : TEXCOORD1;
			#ifdef QUALITY_MEDIUM && PHONG
				float3 texcoord_2 : TEXCOORD2;
				float3 texcoord_3 : TEXCOORD3;
			#endif
			#ifdef NOISE
				float3 texcoord_6 : TEXCOORD6;
			#endif
			#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
				float1 texcoord_7 : TEXCOORD7;
			#endif
		};
		
	#else
		
		OUT.position = getPosition(vertex);
		
		OUT.texcoord_0 = texcoord.xy;
		
		float distance = length(vertex.xyz) * s_depth_range.w;
		
		#ifdef QUALITY_MEDIUM && PHONG
			OUT.texcoord_1 = float4(tangent.x,binormal.x,normal.x,distance);
			OUT.texcoord_2 = float3(tangent.y,binormal.y,normal.y);
			OUT.texcoord_3 = float3(tangent.z,binormal.z,normal.z);
		#else
			#ifdef LEAFS_BILLBOARD
				OUT.texcoord_1 = float4(0.0f,0.0f,1.0f,distance);
			#else
				OUT.texcoord_1 = float4(normal,distance);
			#endif
		#endif
		
		#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
			OUT.texcoord_7.x = alpha_fade;
		#endif
		
	#endif
	
/******************************************************************************\
*
* PlayStation3
*
\******************************************************************************/

#elif PLAYSTATION3
	
	#ifndef VERTEX_LEAF_DEFERRED
		#define VERTEX_LEAF_DEFERRED
		
		struct VERTEX_OUT {
			float4 position : POSITION;
			float2 texcoord_0 : TEXCOORD0;
			float4 texcoord_1 : TEXCOORD1;
			#ifdef QUALITY_MEDIUM && PHONG
				float3 texcoord_2 : TEXCOORD2;
				float3 texcoord_3 : TEXCOORD3;
			#endif
			#ifdef NOISE
				float3 texcoord_8 : TEXCOORD8;
			#endif
			#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
				float1 texcoord_9 : TEXCOORD9;
			#endif
		};
		
	#else
		
		OUT.position = getPosition(vertex);
		
		OUT.texcoord_0 = texcoord.xy;
		
		float distance = length(vertex.xyz) * s_depth_range.w;
		
		#ifdef QUALITY_MEDIUM && PHONG
			OUT.texcoord_1 = float4(tangent.x,binormal.x,normal.x,distance);
			OUT.texcoord_2 = float3(tangent.y,binormal.y,normal.y);
			OUT.texcoord_3 = float3(tangent.z,binormal.z,normal.z);
		#else
			#ifdef LEAFS_BILLBOARD
				OUT.texcoord_1 = float4(0.0f,0.0f,1.0f,distance);
			#else
				OUT.texcoord_1 = float4(normal,distance);
			#endif
		#endif
		
		#ifdef (USE_ALPHA_FADE && ALPHA_FADE) || ANGLE_FADE
			OUT.texcoord_9.x = alpha_fade;
		#endif
		
	#endif
	
#endif
